package Factory;

/**
 * 工厂设计模式
 */
interface IFruit{//定义吃水果的描述
    public void eat();//吃水果
}

class Factory{
    public static IFruit getInstance(String className){
        if ("apple".equals(className)){
            return new Apple();
        }
        if ("orange".equals(className)){
            return new Orange();
        }
        return null;
    }
}

class Apple implements IFruit{
    public void eat(){
        System.out.println("削苹果吃");
    }
}

class Orange implements IFruit{
    public void eat(){
        System.out.println("剥皮吃");
    }
}

public class FactoryTest {
    public static void main(String[] args) {
        IFruit fruit = Factory.getInstance("apple");
        fruit.eat();
    }

}
